package com.cc2019.buke.home.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.cc2019.buke.R;
import com.cc2019.buke.home.entry.Product6;

import java.util.List;

public class PxAdapter extends RecyclerView.Adapter {
    List<Product6> pro_list;
    Context context;
    public PxAdapter(List<Product6> pro_list,Context context){
        this.context = context;
        this.pro_list = pro_list;
    }
    class PxHolder extends RecyclerView.ViewHolder {
        ImageView imageView;
        TextView nameView;
        TextView auterView;
        TextView priceView;
        TextView dataView;
        public PxHolder(@NonNull View itemView) {
            super(itemView);

            imageView = itemView.findViewById(R.id.px_img);
            nameView = itemView.findViewById(R.id.px_name);
            auterView = itemView.findViewById(R.id.px_auter);
            priceView = itemView.findViewById(R.id.px_price);
            dataView = itemView.findViewById(R.id.px_data);

        }
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.px_layout,parent,false);
        PxHolder pxHolder = new PxHolder(view);
        return pxHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        Product6 product6 = pro_list.get(position);
        PxHolder pxHolder = (PxHolder)holder;
        pxHolder.imageView.setImageResource(product6.getImgId());
        pxHolder.nameView.setText(product6.getName());
        pxHolder.auterView.setText(product6.getAuter()+"著，新经典出品");
        pxHolder.priceView.setText("￥"+product6.getPrice());
        pxHolder.dataView.setText(product6.getData()+"条好评");
    }

    @Override
    public int getItemCount() {
        return pro_list.size();
    }
}
